#ifndef PLOTVIEW_H
#define PLOTVIEW_H

#include <string>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_grid.h>
#include <qwt_legend.h>
#include "interfaces.h"
#include "plotdata.h"

class PlotView : public QwtPlot, public PlotObserver
{
    Q_OBJECT

    public:
        PlotView(PlotData *data, int w = 300, int h = 200);
        ~PlotView();
        void Initialize();
        void update();
        int getWidth();
        int getHeight();
        void setWidth(int w);
        void setHeight(int h);
        PlotData *getPlotData();
        void setPlotData(PlotData *data);
        void addCurve(std::string cur_name);
        void showCurve(std::string cur_name);
        void hideCurve(std::string cur_name);
		void boldCurve(std::string cur_name);
		void unBoldCurve(std::string cur_name);
		int getCurveCount();
		void setCurveShowWidget(QWidget *w);
		QWidget *getCurveShowWidget();
		void addLegend(const QString& text);
		void setAxisXTitle(const QString& text);
		void setAxisYTitle(const QString& text);
		// static 
		static Qt::GlobalColor GetColorFromId(int curveId);

    private:
        int m_curveCount;
        int m_width, m_height;
        QwtPlotCurve *curves[MaxCurveCount];
        PlotData *plotdata;
        PlotControllerInterface *plotcontroller;
        void showCurve(int cur_id);
        void hideCurve(int cur_id);
        void boldCurve(int cur_id);
        void unBoldCurve(int cur_id);
		bool m_zoomState;
		QWidget *m_curveShowWid;
		int m_currentBoldCurve;

	protected:	
		void mouseDoubleClickEvent(QMouseEvent *e);

	signals:
		void zoomStateChanged(bool zoom);

    public slots:
        void AddData(double x, double y, int curve);
        void AddData(double x[], double y[]);
        void AddCurve(std::string cur_name);
        void SetCurveState(std::string cur_name, bool state);
		void BoldCurve(std::string cur_name);
};

#endif // PLOTVIEW_H
